package com.xxxy.jsq.action.type;

import com.xxxy.jsq.dao.TypeDao;
import com.xxxy.jsq.model.Type;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/addTypeServlet")
public class addTypeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public addTypeServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        Type model = new Type();
        TypeDao dao = new TypeDao();
        String type_id = request.getParameter("type_id");
        String type_name = request.getParameter("type_name");
        String type_count = request.getParameter("type_count");
        String type_flag = request.getParameter("type_flag");
        String type_years = request.getParameter("type_years");
//
        if (type_id != null && !type_id.equals("")) {
            model.setTypeId(Long.parseLong(type_id));
        }
        if (type_name != null && !type_name.equals("")) {
            model.setTypeName(type_name);
        }
        if (type_count != null && !type_count.equals("")) {
            model.setTypeCount(Integer.parseInt(type_count));
        }
        if (type_flag != null && !type_flag.equals("")) {
            model.setTypeFlag(type_flag);
        }
        if (type_years != null && !type_years.equals("")) {
            model.setTypeYears(type_years);
        }
        String str = dao.add(model);
        PrintWriter out = response.getWriter();
        out.print(str);
        out.flush();
        out.close();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}